﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UploadSingleFile.ascx.cs" Inherits="Besture.UI.Admin.Control.UploadSingleFile" %>
<script language="javascript" type="text/javascript">
    /*上传文件*/
    $(document).ready(function () {
        /*模板文件控件*/
        setTimeout(function () {
            $("#uploadify<%=FileDivID %>").uploadify({
                'fileSizeLimit': '2147483647KB',
                'overrideEvents': ['onSelectError', 'onDialogClose'],
                //返回一个错误，选择文件的时候触发  
                'onSelectError': function (file, errorCode, errorMsg) {
                    switch (errorCode) {
                        case -100:
                            alert("上传的文件数量已经超出系统限制的" + $('#file_upload').uploadify('settings', 'queueSizeLimit') + "个文件！");
                            break;
                        case -110:
                            alert("文件[" + file.name + "]大小超出系统限制！");
                            break;
                        case -120:
                            alert("文件 [" + file.name + "] 大小异常！");
                            break;
                        case -130:
                            alert("文件 [" + file.name + "] 类型不正确！");
                            break;
                    }
                    return false;
                },
                //检测FLASH失败调用  
                'onFallback': function () {
                    alert("您未安装FLASH控件，无法上传！请安装FLASH控件后再试。");
                },
                'swf': '/Admin/PlugIn/jquery.uploadify/uploadify.swf',
                'method': 'get',
                'uploader': '/Admin/Control/UploadFile.aspx',
                'formData': { 'FolderPath': '<%=FolderPath %>' },
                'fileObjName': "ProductPhotoFile",
                'folder': '/Upload/',
                'queueID': 'fileQueue<%=FileDivID %>',
                'auto': true,
                'multi': false,
                'fileTypeExts': "<%=FileTypeExts %>",
                'fileTypeDesc': '<%=FileTypeDesc %>',
                'buttonImage': '/Admin/PlugIn/jquery.uploadify/browse-btn.png',
                'cancelImg': '/Admin/PlugIn/jquery.uploadify/uploadify-cancel.png',
                'width': 120,
                'height': 30,
                'wmode': 'transparent',
                'onUploadSuccess': function (file, data, response) {//上传完成时触发（每个文件触发一次）
                    if (!response) {
                        alert("网络异常，上传失败！");
                    } else {
                        if (data != "0") {
                            $("#<%=hfFileSize.ClientID %>").val(file.size);
                            $("#<%=FileDivID %>_div").remove();
                            var serverDataArgs = data.split("|");
                            var fileUrl = serverDataArgs[0];
                            var fileName = serverDataArgs[1];
                            //添加文件地址同样赋值已存文件文本框，以便验证通过
                            $("#<%=txtFileUrl.ClientID %>").val(fileUrl + "|" + file.name);
                            var strhtml = "";
                            strhtml = strhtml + ("<div class='element' id='<%=FileDivID %>_div'>");
                            strhtml = strhtml + ("    <div>");
                            strhtml = strhtml + ("        文件【" + file.name + "】已上传成功");
                            strhtml = strhtml + ("    </div>");
                            strhtml = strhtml + ("</div>");
                            $("#<%=FileDivID %>").append(strhtml);
                        }
                    }
                }

            });
        }, 10);
    });
</script>
<style type="text/css">
    .uploadify-button
    {
        background-color: transparent;
        border: none;
        padding: 0;
    }
    .uploadify:hover .uploadify-button
    {
        background-color: transparent;
    }
</style>
<img src="<%=RequiredFileUrl %>" align="absMiddle" style="float: left; margin-top: 10px;" />
<div style="float: left">
    <!--上传模板文件控件-->
    <div style="height: 50px;min-width: 150px; border: 1px dashed #999999; background-color: #FFFFFF; padding: 5px;">
        <span style="font-size: 95%; color: #666666" id="tipsSpan">※<%=Tips%></span>
        <!--上传模板文件控件-->
        <input type="file" name="uploadify<%=FileDivID %>" id="uploadify<%=FileDivID %>" />&nbsp;
    </div>
    <div id="fileQueue<%=FileDivID %>" style="width: 100%;">
    </div>
    <div class="uploadSingleFileDiv"  id="<%=FileDivID %>">
        <%=InitText %>
    </div>
    <!--文件地址-->
    <asp:TextBox runat="server" ID="txtFileUrl" style="display: none"></asp:TextBox>
    <asp:HiddenField ID="hfFileSize" runat="server" />
</div>
